package redis

import "time"

func (c *Redis_Class) Del(db int, key string) int64 {
	ret, err := c.GetDB(db).Del(key).Result()
	if err != nil && c.RunErrHandle(err) {
		return c.Del(db, key)
	}
	return ret
}

func (c *Redis_Class) Exits(db int, key string) int64 {
	ret, err := c.GetDB(db).Exists(key).Result()
	if err != nil && c.RunErrHandle(err) {
		return c.Exits(db, key)
	}
	return ret
}

func (c *Redis_Class) Get(db int, key string) string {
	ret, err := c.GetDB(db).Get(key).Result()
	if err != nil && c.RunErrHandle(err) {
		return c.Get(db, key)
	}
	return ret
}

func (c *Redis_Class) Set(db int, key string, value interface{}, ttl time.Duration) string {
	ret, err := c.GetDB(db).Set(key, value, ttl).Result()
	if err != nil && c.RunErrHandle(err) {
		return c.Set(db, key, value, ttl)
	}
	return ret
}

func (c *Redis_Class) SetNx(db int, key string, value interface{}, ttl time.Duration) bool {
	//不存在才设置 过期时间 nx ex
	ret, err := c.GetDB(db).SetNX(key, value, ttl).Result()
	if err != nil && c.RunErrHandle(err) {
		return c.SetNx(db, key, value, ttl)
	}
	return ret
}
